package org.asiainfo.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.asiainfo.system.domain.vo.AnnouncementSendVo;
import org.springframework.validation.annotation.Validated;
import org.asiainfo.system.service.SysAnnouncementSendService;
import org.asiainfo.system.domain.vo.SysAnnouncementSendVo;
import org.asiainfo.system.domain.bo.SysAnnouncementSendBo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.asiainfo.common.mybatis.stream.core.page.PageQuery;
import org.asiainfo.common.mybatis.stream.core.page.TableDataInfo;
import org.asiainfo.common.core.domain.R;
import org.asiainfo.common.web.core.BaseController;
import jakarta.validation.constraints.*;
import org.asiainfo.common.core.validate.AddGroup;
import org.asiainfo.common.core.validate.EditGroup;

import java.util.List;

/**
 * 用户通告阅读标记表
 *
 * @author dotor-ww
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sysAnnouncementSend")
public class SysAnnouncementSendController extends BaseController {

    private final SysAnnouncementSendService sysAnnouncementSendService;

    /**
     * 分页查询
     *
     * @param sysAnnouncementSendBo 筛选条件
     * @param pageQuery             分页对象
     * @return 查询结果
     */
    @SaCheckPermission("system:sysAnnouncementSend:list")
    @GetMapping("/list")
    public TableDataInfo<SysAnnouncementSendVo> list(SysAnnouncementSendBo sysAnnouncementSendBo, PageQuery pageQuery) {
        return sysAnnouncementSendService.queryPageList(sysAnnouncementSendBo, pageQuery);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public R<SysAnnouncementSendVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        return R.ok(sysAnnouncementSendService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param sysAnnouncementSendBo 实体
     * @return 新增结果
     */
    @PostMapping
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysAnnouncementSendBo sysAnnouncementSendBo) {
        return toAjax(sysAnnouncementSendService.insertByBo(sysAnnouncementSendBo));
    }

    /**
     * 编辑数据
     *
     * @param sysAnnouncementSendBo 实体
     * @return 编辑结果
     */
    @PutMapping
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysAnnouncementSendBo sysAnnouncementSendBo) {
        return toAjax(sysAnnouncementSendService.updateByBo(sysAnnouncementSendBo));
    }

    /**
     * 删除数据
     *
     * @param ids 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(sysAnnouncementSendService.deleteWithValidByIds(List.of(ids)));
    }

    /**
     * 通过通告ID修改数据
     *
     * @param antId 通告ID
     * @return 修改结果
     */
    @PostMapping("/editByAntIdAndUserId/{antId}")
    public R<Void> editByAntIdAndUserId(@NotNull(message = "主键ID不能为空") @PathVariable Long antId) {
        return toAjax(sysAnnouncementSendService.editByAntIdAndUserId(antId));
    }

    /**
     * 获取我的消息
     *
     * @param title     标题
     * @param pageQuery 分页对象
     * @return 我的消息
     */
    @GetMapping("/getMyAnnouncementSend")
    public TableDataInfo<AnnouncementSendVo> getMyAnnouncementSend(String title, PageQuery pageQuery) {
        return sysAnnouncementSendService.getMyAnnouncementSend(title, pageQuery);
    }

    /**
     * 一键阅读
     *
     * @return 阅读结果
     */
    @PostMapping("/readAll")
    public R<Void> readAll() {
        return toAjax(sysAnnouncementSendService.readAll());
    }
}

